package io.gitee.twoke.generator.engine.impl.persistence.entity.data.impl;

import io.gitee.twoke.generator.engine.impl.cfg.GenerateEngineConfigurationImpl;
import io.gitee.twoke.generator.engine.impl.persistence.TemplateFileDataManager;
import io.gitee.twoke.generator.engine.impl.persistence.entity.*;
import io.gitee.twoke.generator.engine.impl.template.TemplateFile;
import io.gitee.twoke.generator.engine.impl.template.impl.TemplateFileQueryImpl;

import java.util.HashMap;
import java.util.List;

public class MybatisTemplateFileDataManager extends AbstractDataManager<TemplateFileEntity> implements
        TemplateFileDataManager {

  public MybatisTemplateFileDataManager(GenerateEngineConfigurationImpl generateEngineConfiguration) {
    super(generateEngineConfiguration);
  }

  @Override
  public Class<? extends TemplateFileEntity> getManagedEntityClass() {
    return TemplateFileEntityImpl.class;
  }
  
  @Override
  public TemplateFileEntity create() {
    return new TemplateFileEntityImpl();
  }

  @Override
  public long findTemplateFileCountByQueryCriteria(TemplateFileQueryImpl templateFileQuery) {
    return  (Long) getDbSqlSession().selectOne("selectTemplateFileCountByQueryCriteria", templateFileQuery);
  }

  @Override
  public List<TemplateFile> findTemplateFilesByQueryCriteria(TemplateFileQueryImpl templateFileQuery) {
    return getDbSqlSession().selectList("selectTemplateFilesByQueryCriteria", templateFileQuery);
  }

  @Override
  public void deleteTemplateFilesByTemplateId(String templateId) {
    getDbSqlSession().getSqlSession()
            .delete("deleteTemplateFileByTemplateId", new HashMap<String, Object>(){{
              put("templateId", templateId);
            }});
  }
}